package com.hczt.xhminiapp.common.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

public class JsonUtils {

    private static final Gson gson = new Gson();

    public static String toJson(Object object) {
        return gson.toJson(object);
    }

    public static String toJsonWithNull(Object object) {
        Gson gson = new GsonBuilder().serializeNulls().create();
        return gson.toJson(object);
    }

    public static <T> T toObject(String jsonArry, TypeToken type) {
        Gson gson = new GsonBuilder().serializeNulls().create();
        return gson.fromJson(jsonArry, type.getType());
    }
}
